package com.lenovo.nova.widget.ablistview;

import android.content.Context;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.lenovo.nova.util.debug.mylog;

/**
 * Created by scenic on 6/3/15.
 */
public class HoverBigWindowManager {

    private static final String TAG = "HoverBigWindowManager";
    private TwoWayAbsListView mGridView;

    private FrameLayout frameLayout;
    private ImageView imageView;

    private View mCurrentHoverView ;
    private View mLastHoverView;

    public HoverBigWindowManager(TwoWayAbsListView view) {
        mGridView = view;
    }

    Rect rect = new Rect();

    public void onHoverEvent(MotionEvent event) {

        int girdViewLeft = mGridView.getLeft();
        int gridViewTop = mGridView.getTop();

        int x = (int) event.getX();
        int y = (int) event.getY();
        int rawX = (int) event.getRawX();
        int rawY = (int) event.getRawY();
        int position = mGridView.pointToPosition(x, y);
        if(position > 0){
            View view = mGridView.getChildAt(position - mGridView.getFirstVisiblePosition());
            if(mCurrentHoverView != view){
                mylog.d(TAG, "position " + position + " x " + x + " raw " + event.getRawX() + " y " + y + " rawy " + event.getRawY());
                mylog.d(TAG,"view tag " + view.getTag());

                view.getGlobalVisibleRect(rect);
                mylog.d(TAG, "local visible rect is " + rect);
                mLastHoverView = mCurrentHoverView;
                mCurrentHoverView = view;

                if(mLastHoverView != null){
                    mylog.d(TAG,"mLastHoverView " + mLastHoverView.getTag());
                }

                if(mCurrentHoverView != null){
                    mylog.d(TAG," mCurrentHoverView " + mCurrentHoverView.getTag());
                }

            }
        }
    }

    public void onAttachedToWindow(Context context) {
        frameLayout = new FrameLayout(context);
        ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(400,400);
        frameLayout.setLayoutParams(params);


        imageView = new ImageView(context);
        frameLayout.addView(imageView);

    }

    public void onDetachedFromWindow() {

    }
}
